package com.aaa.controller;

import com.aaa.common.domain.Role;
import com.aaa.common.query.RoleQuery;
import com.aaa.common.result.Result;
import com.aaa.service.impl.RoleServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/role")
public class RoleController {

    @Autowired
    RoleServiceImpl service;

    /**
     * 查询角色
     */
    @PostMapping("/listP")
    public Result listPersonRenter(@RequestBody RoleQuery roleQuery){
        Result result = service.listRole(roleQuery);
        System.out.println(result);
        return result;
    }

    /**
     * 添加角色
     * @return
     */
    @PostMapping("/add")
    public Result addPersonRenter(@RequestBody Role role){
        boolean b = service.addRole(role);
        if (b==true){
            return Result.success(b);
        }
        return Result.error("error");
    }

    @GetMapping("/checkbox")
    public Result queryRole(){
        Result result = service.queryRoleCheckbox();
        return result;
    }


    /**
     * 通过id查询该数据
     * @param id
     * @return
     */
    @GetMapping("getId")
    public Result getId(Integer id){
        return service.listRoleById(id);
    }

    /**
     * 修改角色
     * @return
     */
    @PostMapping("/update")
    public Result updatePersonRenter(@RequestBody Role role){
        boolean b = service.updateRole(role);
        if (b==true){
            return Result.success(b);
        }
        return Result.error("error");
    }

    /**
     * 删除角色
     * @return
     */
    @DeleteMapping("/delete")
    public Result delPersonRenter(String ids){
        boolean b = service.deleteRole(ids);
        if (b==true){
            return Result.success(b);
        }
        return Result.error("error");
    }
}
